package cn.tedu.charging.device.controller;

import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.common.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import cn.tedu.charging.device.service.StationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备服务接口
 */
@Api(tags = "设备场站相关接口")
@Slf4j
@RestController
@RequestMapping("/device")
public class DeviceController {

    @Autowired  //14.2添加
    private StationService stationService;

    @ApiOperation("获取场站信息")
    @GetMapping("/station/info/{gunId}")
    public JsonResult getStationInfo(@PathVariable("gunId") Integer gunId){
        log.info("获取场站信息-{}",gunId);
        StationInfoVO vo = new StationInfoVO();
        vo.setOperatorId(1);
        vo.setStationId(1);
        //JsonResult jsonResult = new JsonResult();
        //jsonResult.setData(vo);
        //jsonResult.setCode(2000);
        return JsonResult.ok(vo);
    }

    @ApiOperation("更新枪状态")
    @PostMapping("/station/gun/status/update")
    public JsonResult updateGunStatus(@RequestBody GunStatusUpdateParam gunStatusUpdateParam){
        log.info("更新枪的状态-{}",gunStatusUpdateParam);
        return JsonResult.ok(true);
    }

    /**
     * 14.2添加
     * @param longitude 经度
     * @param latitude 维度
     * @param radius 距离
     * @return
     */
    @ApiOperation("附近的充电站")
    @GetMapping("/station/near/")
    public JsonResult getNearStations(Double longitude, Double latitude,Double radius){
        log.info("获取附近的充电站-经度:{},维度:{},距离:{}",longitude,latitude,radius);
        List<StationInfoVO> stationInfoVOS =  stationService.getNearStations(longitude,latitude,radius);
        //给StationInfoVO添加属性
        return JsonResult.ok(stationInfoVOS);
    }

    /**
     * 获取充电桩详情 16.1添加方法，让微信开发工具里手机端能点开看到站点详情
     * @param id id
     * @return
     */
    @ApiOperation("场站详情")
    @GetMapping("/station/detail/{id}")
    public JsonResult getStationDetail(@PathVariable("id") Integer id){
        log.info("场站详情-id:{}",id);
        StationInfoVO stationInfoVOS =  stationService.getStationDetail(id);
        return JsonResult.ok(stationInfoVOS);
    }

}
